Add a function to get affected area for background
authorMatthias Clasen <mclasen@redhat.com>
Wed, 20 Jan 2016 14:41:01 +0000 (09:41 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 20 Jan 2016 14:41:01 +0000 (09:41 -0500)
The new function, gtk_render_background_get_clip answers the
question: what pixels are affected if I call gtk_render_background ?

The long-term goal is to have APIs that answer this question for
all rendering primitives.

docs/reference/gtk/gtk3-sections.txt
gtk/gtkrender.c
gtk/gtkrender.h

index fe439c97f1d091a04fa77a3854f914c594bf5f69..fd7c85ab41ee501bca4f67dd1752cad98f979bbc 100644 (file)
@@ -6258,6 +6258,7 @@ gtk_border_free
 <SUBSECTION>
 gtk_render_arrow
 gtk_render_background
+gtk_render_background_get_clip
 gtk_render_check
 gtk_render_expander
 gtk_render_extension
index 6be35a0c21d189b6bd5274939bcac834865a551d..42cd58f7f284faf0c2f8d959abba73eb067fb52b 100644 (file)
@@ -282,6 +282,39 @@ gtk_render_background (GtkStyleContext *context,
   cairo_restore (cr);
 }
 
+/**
+ * gtk_render_background_get_clip:
+ * @context: a #GtkStyleContext
+ * @x: X origin of the rectangle
+ * @y: Y origin of the rectangle
+ * @width: rectangle width
+ * @height: rectangle height
+ * @out_clip: (out): return location for the clip
+ *
+ * Returns the area that will be affected (i.e. drawn to) when
+ * calling gtk_render_background() for the given @context and
+ * rectangle.
+ *
+ * Since: 3.20
+ */
+void
+gtk_render_background_get_clip (GtkStyleContext *context,
+                                gdouble          x,
+                                gdouble          y,
+                                gdouble          width,
+                                gdouble          height,
+                                GdkRectangle    *out_clip)
+{
+  GtkBorder shadow;
+
+  _gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW), &shadow);
+
+  out_clip->x = floor (x) - shadow.left;
+  out_clip->y = floor (y) - shadow.top;
+  out_clip->width = ceil (width) + shadow.left + shadow.right;
+  out_clip->height = ceil (height) + shadow.top + shadow.bottom;
+}
+
 /**
  * gtk_render_frame:
  * @context: a #GtkStyleContext
index ea4b84ae63c8b373ca9e952665babf6213bf58f0..81566c5452d1da8f4de524e72aaee7705589b899 100644 (file)
@@ -59,6 +59,15 @@ void        gtk_render_background  (GtkStyleContext     *context,
                                     gdouble              y,
                                     gdouble              width,
                                     gdouble              height);
+
+GDK_AVAILABLE_IN_3_20
+void        gtk_render_background_get_clip  (GtkStyleContext     *context,
+                                             gdouble              x,
+                                             gdouble              y,
+                                             gdouble              width,
+                                             gdouble              height,
+                                             GdkRectangle        *out_clip);
+
 GDK_AVAILABLE_IN_ALL
 void        gtk_render_frame       (GtkStyleContext     *context,
                                     cairo_t             *cr,